<template>

  <a-modal v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width" :ok-text="LAYER.okText"
           :align-center="LAYER.alignCenter" :top="LAYER.top"
           :closable="LAYER.closable" :unmount-on-close="LAYER.unmountOnClose"
           :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose" :ok-loading="LAYER.okLoading"
           :on-before-ok="onSubmit" @cancel="onCancel()" >

<!--    {{record}}-->
    <a-button type="primary" style="position: absolute; z-index: 100 ; right: 25px; top: 28px" @click="ev => show = !show">{{ show?"预览":"修改" }}</a-button>
    <div v-if="show">
        <smart-rich-editor v-model="record.remarks" />

    </div>
    <div v-else v-html="record.remarks"></div>
    <a-empty v-if="EmptyUtil.isEmptyObject(record.remarks)&&!show"/>


  </a-modal>

</template>
<script lang="ts" setup>

import {ref} from "vue";
import {LocalDrawer} from "@/libs/core";
import {SystemHttp} from "../resource/http";
import {EmptyUtil, MsgUtil} from "@/utils";

const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])
const show = ref(true)
show.value = EmptyUtil.isEmptyString(props.record.remarks)
// const {member} = props.record
const service = new LocalDrawer(emit)

const {LAYER, onCancel} = service
service.setMD("备注", "确认")

const onSubmit = async () => {

  if (EmptyUtil.isEmptyString(props.record.remarks)){
    MsgUtil.message("备注内容不能为空")
    return false
  }

  const {code} = await SystemHttp.updateRemarks(props.record.id,{content:props.record.remarks})
  if (code === 0){
    MsgUtil.notify("操作成功","修改备注成功")
  }
  onCancel()
}

</script>

